package com.aooci.ordercat.jsf;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;

import org.apache.log4j.Logger;
import org.primefaces.component.tabview.TabView;
import org.primefaces.event.TabChangeEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.aooci.ordercat.domain.DiningTable;
import com.aooci.ordercat.domain.ItemCategory;
import com.aooci.ordercat.service.DashboardService;
import com.aooci.ordercat.vo.OperatedOrderVo;

//@ManagedBean
@RequestScoped
@Component
public class DiningHallController implements Serializable{

	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(DiningHallController.class);
	
	public static final int DEFAULT_NUMBER_OF_CLIENT_FOR_DINING_TABLE = 2;
	
	@Autowired
	@Qualifier("dashboardService")
	private transient DashboardService dashboardService;
	
	
	private DiningTable selectedDiningTable;
	
	private int nofClient;
	
	private OperatedOrderVo orderOperationVo;


	public void selectedDiningTableVoListener(ActionEvent event) {
		this.selectedDiningTable = (DiningTable)event.getComponent().getAttributes().get("selectedTableVo");
		this.selectedDiningTable.setNofClient(DEFAULT_NUMBER_OF_CLIENT_FOR_DINING_TABLE);
		log.info("Operator select table: " + this.selectedDiningTable.getLabel());
	}

	public void selectDiningTable(int diningTableId){
		System.out.println("diningTableId = " + diningTableId);
		//orderOperationVo = dashboardService.loadOrderOperationVoToDiningTable(diningTableId);
	}
	
	public List<DiningTable> loadDiningTables(int diningTableCategoryId){
		//return dashboardService.loadDiningTables();
		return dashboardService.loadDiningTablesByCategoryId(diningTableCategoryId);
	}


	
	public OperatedOrderVo getOrderOperationVo() {
		return orderOperationVo;
	}
	
	public void ordertItemFromCategore(int itemId, int itemCount) {
		System.out.println("diningTableId = ");
	}
	
	public List<ItemCategory> getItemCategories(){
		return dashboardService.loadItemCategories();
	}

	/**
	 * @return the nofClient
	 */
	public int getNofClient() {
		return nofClient;
	}

	/**
	 * @param nofClient the nofClient to set
	 */
	public void setNofClient(int nofClient) {
		this.nofClient = nofClient;
	}

	/**
	 * @return the selectedDiningTableVo
	 */
	public DiningTable getSelectedDiningTable() {
		return selectedDiningTable;
	}

	/**
	 * @param selectedDiningTableVo the selectedDiningTableVo to set
	 */
	public void setSelectedDiningTable(DiningTable selectedDiningTable) {
		this.selectedDiningTable = selectedDiningTable;
	}

}
